package org.xlp.auto.create;

import org.xlp.assertion.AssertUtils;
import org.xlp.auto.create.exception.AutoCreatorDataLoseException;
import org.xlp.auto.create.util.AutoCreatorUtils;
import org.xlp.utils.XLPStringUtil;

/**
 * Description: Service java文件自动创建类
 * <br/>date: 2023/12/01 11:05
 *
 * @version 1.0
 * @author: xlp
 */
public class ServiceAutoCreator extends AbstractAutoCreator{
    public ServiceAutoCreator() {
        setSubPackageName(Constants.SERVICE_SUB_PACKAGE_NAME);
        setClassType(ClassType.INTERFACE);
    }

    /**
     * 构造函数
     * @param entityName
     * @throws NullPointerException 假如参数为null，则抛出该异常
     */
    public ServiceAutoCreator(String entityName) {
        this();
        setEntityName(entityName);
        String subPkgName = Constants.SERVICE_SUB_PACKAGE_NAME + "." + entityName.toLowerCase();
        setSubPackageName(subPkgName);
    }

    /**
     * 构造函数
     * @param abstractAutoCreator
     * @throws NullPointerException 假如参数为null，则抛出该异常
     */
    public ServiceAutoCreator(AbstractAutoCreator abstractAutoCreator){
        AssertUtils.isNotNull(abstractAutoCreator, "entityAutoCreator parameter must not be null!");
        AutoCreatorUtils.autoCreatorConvert(this, abstractAutoCreator);

        String subPkgName = Constants.SERVICE_SUB_PACKAGE_NAME + "." + abstractAutoCreator.getEntityName().toLowerCase();
        setSubPackageName(subPkgName);
        setClassType(ClassType.INTERFACE);
    }

    /**
     * java文件注解类容
     *
     * @return
     */
    @Override
    protected String makeAnnotationContent() {
        return XLPStringUtil.EMPTY;
    }

    /**
     * 获取java文件名称
     *
     * @return
     * @throws AutoCreatorDataLoseException 假如获取失败，则抛出该异常
     */
    @Override
    protected String getFileName() throws AutoCreatorDataLoseException {
        if (XLPStringUtil.isEmpty(getEntityName())){
            throw new AutoCreatorDataLoseException("实体名称未设置。");
        }
        return getEntityName() + "Service" + Constants.JAVA_FILE_SUFFIX;
    }
}
